package com.huidz.calendar.activityadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.huidz.calendar.R;
import com.huidz.calendar.mainfragment.AlmanacFragment;
import com.huidz.calendar.util.Apiutils;

import java.util.ArrayList;

public class XianDaiWenAdapter extends BaseAdapter {
    ArrayList<String> list;
    Context context;

    public XianDaiWenAdapter(ArrayList<String> list, Context context) {
        // TODO Auto-generated constructor stub
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list != null ? list.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        convertView = LayoutInflater.from(context).inflate(R.layout.fragment_xiandaiwenlistitem, null);
        init i = new init();
        i.list_yi_title = convertView.findViewById(R.id.list_yi_title);
        i.xdw_title_msg = convertView.findViewById(R.id.xdw_title_msg);
        i.list_ji_title = convertView.findViewById(R.id.list_ji_title);
        i.list_yi_msg = convertView.findViewById(R.id.list_yi_msg);
        i.list_ji_msg = convertView.findViewById(R.id.list_ji_msg);
        i.xdw_title_text = convertView.findViewById(R.id.xdw_title_text);
        i.list_yi_reld = convertView.findViewById(R.id.list_yi_reld);
        i.list_ji_reld = convertView.findViewById(R.id.list_ji_reld);
        i.settextview = convertView.findViewById(R.id.settextview);
        i.settextview1 = convertView.findViewById(R.id.settextview1);
        if (position != 0) {
            i.list_yi_reld.setVisibility(View.GONE);
            i.list_ji_reld.setVisibility(View.GONE);
            i.list_ji_title.setVisibility(View.GONE);
            i.list_ji_msg.setVisibility(View.GONE);
        }
        if (position != 2) {
            i.xdw_title_msg.setVisibility(View.GONE);
        }
        switch (position) {
            case 0:
                i.xdw_title_text.setText("宜忌");
                i.list_yi_msg.setText(AlmanacFragment.SelectXDW(AlmanacFragment.strarray[0]));
                i.list_yi_title.setText(AlmanacFragment.strarray[0]);
                i.list_ji_title.setText(AlmanacFragment.strarrays[0]);
                i.list_ji_msg.setText(AlmanacFragment.SelectXDW(AlmanacFragment.strarrays[0]));
                for (int s = 1; s < AlmanacFragment.strarray.length; s++) {
                    TextView textView = new TextView(context);
                    TextView textView1 = new TextView(context);
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                    lp.setMargins(32, 0, 0, 15);
                    textView.setLayoutParams(lp);
                    textView.setText(AlmanacFragment.strarray[s]);
                    textView.setTextColor(context.getResources().getColor(R.color.title_color));
                    textView.setTextSize(14);
                    textView1.setLayoutParams(lp);
                    textView1.setText(AlmanacFragment.SelectXDW(AlmanacFragment.strarray[s]));
                    textView1.setTextColor(context.getResources().getColor(R.color.text_black));
                    textView1.setTextSize(14);
                    i.settextview.addView(textView);
                    i.settextview.addView(textView1);
                }
                for (int s1 = 1; s1 < AlmanacFragment.strarrays.length; s1++) {
                    TextView textView2 = new TextView(context);
                    TextView textView3 = new TextView(context);
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                    lp.setMargins(32, 0, 0, 15);
                    textView2.setLayoutParams(lp);
                    textView2.setText(AlmanacFragment.strarrays[s1]);
                    textView2.setTextColor(context.getResources().getColor(R.color.jicolor));
                    textView2.setTextSize(14);
                    textView3.setLayoutParams(lp);
                    textView3.setText(AlmanacFragment.SelectXDW(AlmanacFragment.strarrays[s1]));
                    textView3.setTextColor(context.getResources().getColor(R.color.text_black));
                    textView3.setTextSize(14);
                    i.settextview1.addView(textView2);
                    i.settextview1.addView(textView3);
                }
                break;
            case 1:
                i.xdw_title_text.setText("冲煞");
                i.list_yi_msg.setText("本日对属" + Apiutils.ShengXiao + "的人不太有利");
                i.list_yi_title.setText(Apiutils.ChongSha);
                TextView textView = new TextView(context);
                LinearLayout.LayoutParams lpt = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                lpt.setMargins(32, 0, 0, 15);
                textView.setLayoutParams(lpt);
                textView.setText("本日煞神方位在" + Apiutils.FangWei + "方,向" + Apiutils.FangWei + "方行事要小心。");
                textView.setTextColor(context.getResources().getColor(R.color.text_black));
                textView.setTextSize(14);
                i.settextview.addView(textView);
                break;
            case 2:
                i.xdw_title_text.setText("值神");
                i.list_yi_msg.setText(AlmanacFragment.zhishen);
                i.list_yi_title.setText(Apiutils.GET_ZHISHEN);
                break;
            case 3:
                i.xdw_title_text.setText("五行");
                i.list_yi_title.setText(Apiutils.WuXing);
                i.list_yi_msg.setText(AlmanacFragment.SelectXDW(Apiutils.WuXing));
                break;
            case 4:
                i.xdw_title_text.setText("吉神");
                i.list_yi_title.setText(AlmanacFragment.jishen[0]);
                i.list_yi_msg.setText(AlmanacFragment.SelectXDW(AlmanacFragment.jishen[0]));
                for (int s1 = 1; s1 < AlmanacFragment.jishen.length; s1++) {
                    TextView textView2 = new TextView(context);
                    TextView textView3 = new TextView(context);
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                    lp.setMargins(32, 0, 0, 15);
                    textView2.setLayoutParams(lp);
                    textView2.setText(AlmanacFragment.jishen[s1]);
                    textView2.setTextColor(context.getResources().getColor(R.color.title_color));
                    textView2.setTextSize(14);
                    textView3.setLayoutParams(lp);
                    textView3.setText(AlmanacFragment.SelectXDW(AlmanacFragment.jishen[s1]));
                    textView3.setTextColor(context.getResources().getColor(R.color.text_black));
                    textView3.setTextSize(14);
                    i.settextview.addView(textView2);
                    i.settextview.addView(textView3);
                }
                break;
            case 5:
                i.xdw_title_text.setText("凶神");
                i.list_yi_title.setText(AlmanacFragment.xiongshen[0]);
                i.list_yi_msg.setText(AlmanacFragment.SelectXDW(AlmanacFragment.xiongshen[0]));
                for (int s1 = 1; s1 < AlmanacFragment.xiongshen.length; s1++) {
                    TextView textView2 = new TextView(context);
                    TextView textView3 = new TextView(context);
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                    lp.setMargins(32, 0, 0, 15);
                    textView2.setLayoutParams(lp);
                    textView2.setText(AlmanacFragment.xiongshen[s1]);
                    textView2.setTextColor(context.getResources().getColor(R.color.title_color));
                    textView2.setTextSize(14);
                    textView3.setLayoutParams(lp);
                    textView3.setText(AlmanacFragment.SelectXDW(AlmanacFragment.xiongshen[s1]));
                    textView3.setTextColor(context.getResources().getColor(R.color.text_black));
                    textView3.setTextSize(14);
                    i.settextview.addView(textView2);
                    i.settextview.addView(textView3);
                }
                break;
            case 6:
                i.xdw_title_text.setText("胎神");
                i.list_yi_msg.setText(AlmanacFragment.SelectXDW(Apiutils.GET_TAISHEN));
                i.list_yi_title.setText(Apiutils.GET_TAISHEN);
                break;
            case 7:
                i.xdw_title_text.setText("彭祖");
                i.list_yi_msg.setText(AlmanacFragment.SelectXDW(Apiutils.Pengzuone));
                i.list_yi_title.setText(Apiutils.Pengzuone);
                TextView textView2 = new TextView(context);
                TextView textView3 = new TextView(context);
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                lp.setMargins(32, 0, 0, 15);
                textView2.setLayoutParams(lp);
                textView2.setText(Apiutils.Pengzutwo);
                textView2.setTextColor(context.getResources().getColor(R.color.title_color));
                textView2.setTextSize(14);
                textView3.setLayoutParams(lp);
                textView3.setText(AlmanacFragment.SelectXDW(Apiutils.Pengzutwo));
                textView3.setTextColor(context.getResources().getColor(R.color.text_black));
                textView3.setTextSize(14);
                i.settextview.addView(textView2);
                i.settextview.addView(textView3);
                break;
            case 8:
                i.xdw_title_text.setText("星宿");
                i.list_yi_msg.setText(AlmanacFragment.SelectXDW(Apiutils.XingXiu + "宿星"));
                i.list_yi_title.setText(Apiutils.XingXiu);
                break;
        }
        convertView.setTag(i);
        return convertView;
    }

    public static class init {
        //首页list的子控件
        TextView list_yi_title, xdw_title_msg, list_ji_title, list_yi_msg, list_ji_msg, xdw_title_text;
        RelativeLayout list_yi_reld, list_ji_reld;
        LinearLayout settextview, settextview1;
    }
}

